import 'package:flutter/material.dart';

import '../public.dart';

/// 本地化
class LocalProvider with ChangeNotifier {
  static const localeValueList = ['en-US', 'zh-CN'];

  int _localeIndex = 0;

  int get localeIndex => _localeIndex;

  LocalProvider();

  Locale get locale {
    if (_localeIndex >= 0) {
      var value = localeValueList[_localeIndex].split("-");
      LogUtil.v(value);
      return Locale(value[0], value[1]);
    }
    // 跟随系统
    return null;
  }

  switchLocale(int index) {
    _localeIndex = index;
    I18n.locale = locale;
    notifyListeners();
  }
}
